package com.dyc.mapper;

import com.dyc.pojo.Emp;
import com.dyc.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 员工
 */
@Mapper
public interface EmpMapper {
    //原始分页查询原理
    /* *//**
     * 查询总记录数
     *
     * @return
     *//*
    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id")
    public long count();

    *//**
     * 分页查询
     * @return
     *//*
    @Select("select e.* ,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
            "order by e.update_time desc limit #{start},#{limit}")
    public List<Emp> list(Integer start, Integer limit);
*/

    /*@Select("select e.* ,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
            "order by e.update_time desc")*/
    //public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    /**
     * 条件查询员工信息
     *
     * @param empQueryParam
     * @return
     */
    public List<Emp> list(EmpQueryParam empQueryParam);

    //添加员工
    //获取主键值,返回给id
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender,phone,job,salary,image,entry_date, dept_id, create_time, update_time) " +
            "values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime}) ")
    void insert(Emp emp);

    /**
     * 根据id批量删除
     *
     * @param ids
     */
    void deleteById(List<Integer> ids);

    /**
     * 根据id查询员工信息和工作经历
     *
     * @param id
     * @return
     */
    Emp getInfoById(Integer id);

    /**
     * 根据id更新员工信息
     *
     * @param emp
     */
    void updateById(Emp emp);

    /**
     * 登录信息查询
     *
     * @param emp
     * @return
     */
    @Select("select id ,username , name  from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);

    /**
     * 修改密码
     * @param id
     * @param password
     */
    @Update("update emp set password = #{password} where id = #{id}")
    void changePassword(Integer id, String password);

   /* @Update("update emp set password = #{emp.getPassword} where id = #{emp.getId}")
    void changePassword(Emp emp);*/


}
